﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SPA_Gallery
{
    public partial class Uploader : DotNetNuke.Entities.Modules.PortalModuleBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                cmdBack.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL();
                DotNetNuke.Framework.ServicesFramework.Instance.RequestAjaxAntiForgerySupport();

            hdnModuleId.Value = this.ModuleId.ToString();
            hdnPortalId.Value = this.PortalId.ToString();
            bindDdlFolder();
                //Ajout des scripts
                Page.ClientScript.RegisterClientScriptInclude("fileupload", ResolveClientUrl("Scripts/jquery.fileupload.js"));
                Page.ClientScript.RegisterClientScriptInclude("iframTransport", ResolveClientUrl("Scripts/jquery.iframe-transport.js"));
            }

        }
        private void bindDdlFolder()
        {
            string rootFolder = string.Format(Components.Constants.RootFolderPathScheme + "/", this.ModuleId);
            //DotNetNuke.Services.FileSystem.FolderManager foldC = DotNetNuke.Services.FileSystem.FolderManager.Instance;
            DotNetNuke.Services.FileSystem.FolderInfo rootFolderInfo;
            if (!DotNetNuke.Services.FileSystem.FolderManager.Instance.FolderExists(this.PortalId, rootFolder))
            {
                rootFolderInfo = (DotNetNuke.Services.FileSystem.FolderInfo)DotNetNuke.Services.FileSystem.FolderManager.Instance.AddFolder(this.PortalId, rootFolder);
            }
            else
            {
                rootFolderInfo = (DotNetNuke.Services.FileSystem.FolderInfo)DotNetNuke.Services.FileSystem.FolderManager.Instance.GetFolder(this.PortalId, rootFolder);
            }
            List<DotNetNuke.Services.FileSystem.IFolderInfo> lstFolders = DotNetNuke.Services.FileSystem.FolderManager.Instance.GetFolders(rootFolderInfo).ToList();
            lstFolders.Insert(0, rootFolderInfo);
            pGal.DataSource = from myFolder in lstFolders
                              select new { FolderPath = myFolder.FolderPath.Replace(rootFolder,"/"), FolderId =myFolder.FolderID};
           pGal.DataTextField = "FolderPath";
           pGal.DataValueField = "FolderId";
           pGal.DataBind();
        }

       
    }
}